<template>
	<view class="viewpage">
		<u-navbar :is-back="true" back-text="扫码解锁" :back-text-style="navcolor" back-icon-color="#ffff"
			:background="background" :border-bottom="false" title-color="#ffff" title-size="36">
		</u-navbar>
		<!-- <u-upload ref="uUpload" action="http://192.168.1.188:8088/pd/sys/common/upload" :auto-upload="true" ></u-upload> -->
		<view class="title">请输入充电站编号</view>


		<view class="messageinput">
			<text class="textP">P</text> <u-message-input :focus="true" :breathe="false" :bold="false" :maxlength="6" font-size="40" width="90"
				active-color="#0A348B" :value="deviceCode" @change="changecode">
			</u-message-input>
		</view>
		<view class="_btns">
			<view class="btn btn_1" @click="checkcharing">确认</view>
			<view class="btn btn_2" @click="toScale">扫码充电</view>
		</view>
		<view class="copyright">
			<view>Copyright©2021 </view>
			<view>领程工场软件科技 IOT物联网平台</view>
		</view>
	</view>
</template>

<script>
	import { findCharginByCode } from '../../api/charging';
	export default {
		data() {
			return {
				background: {
					backgroundColor: 'transparent',
				},
				navcolor: {
					color: '#ffff'
				},
				deviceCode:''
			};
		},
		methods: {
			toScale() {
				// 只允许通过相机扫码
				uni.scanCode({
				    onlyFromCamera: true,
				    success: function (res) {
				
				        console.log('条码内容：' , res.result);
						findCharginByCode({
							deviceCode: res.result
						}).then(res2 => {
							if (res2.code == 200) {
								
								
								uni.navigateTo({
								
									url:'../Charging-pile/select-port?deviceCode='+res2.result.pdCharginWxd.deviceCode
								})
								console.log('跳转');
							}else if(res2.code == 2001){
								uni.showToast({
									title: '充电站不存在',
									duration: 2000,
									icon:'error'
								});
							}
						});
				    }
				});
			},
			changecode(e) {
				this.deviceCode = e
							console.log('内容改变，当前值为：' + e);
			},
			checkcharing(){
					// uni.showToast({
					// 	icon:'error',
					//     title: '请输入7位数字的充电站',
					//     duration: 2000
					// });
				let deviceCode =	'P' + this.deviceCode 
				findCharginByCode({deviceCode:deviceCode}).then(res=>{
					console.log(res)
					
					if(res.code == 200){
						uni.navigateTo({
							url:'./select-port?deviceCode='+deviceCode
						})
					}
				})
			}
		},
		onLoad() {

		}
	}
</script>

<style lang="scss">
	
	::v-deep .messageinput{
		display: flex;
		justify-content: center;
		align-items: center;
		.textP{
			margin-right: 30rpx;
			font-size: 80rpx;
			font-weight: bold;
			color: #FFFFFF;
		}
	}
	::v-deep .messageinput .u-char-box .u-box-active {
	  color: #0A348B;
	  border: 3rpx solid #0A348B !important;
	  box-shadow: 0px 0px 3px 2px rgba(255, 255, 255, 0.71);
	}
	page {
		height: 100%;
	}

	.viewpage {
		width: 100%;
		min-height: 100%;
		background-image: url("http://bytedev-gd8d.oss-cn-shenzhen.aliyuncs.com/upload/2021-9-10/1631259459022编组 8@2x.png");
		background-size: 100%;
	}

	._btns {
		margin-top: 86rpx;
		padding: 0 30rpx;

		.btn {
			width: 690rpx;
			height: 100rpx;
			border-radius: 20rpx;
			font-size: 36rpx;
			font-weight: 400;
			line-height: 100rpx;
			text-align: center;
		}

		.btn_1 {
			background: #FFFFFF;
			color: #0A348B;
		}

		.btn_2 {
			margin-top: 30rpx;
			color: #fff;
			background-color: rgba(255, 255, 255, 0.3);
		}
	}

	.title {
		width: 100%;
		text-align: center;
		font-size: 40rpx;
		font-weight: 400;
		color: #ffffff;
		margin: 72rpx auto;
	}
</style>
